package com.cf.studiomanage.mapper;

import com.cf.studiomanage.entity.Finance;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FinanceMapper {

    @Insert("INSERT INTO finance(type, amount, description, user_id) VALUES(#{type}, #{amount}, #{description}, #{userId})")
    int addRecord(Finance finance);

    @Select("SELECT * FROM finance ORDER BY created_at DESC")
    List<Finance> getAll();

    @Select("SELECT * FROM finance WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<Finance> getByUser(Long userId);

    @Delete("DELETE FROM finance WHERE id = #{id}")
    int deleteById(Long id);
}
